package com.sbl.bajw.util;

import it.sauronsoftware.jave.AudioAttributes;
import it.sauronsoftware.jave.Encoder;
import it.sauronsoftware.jave.EncoderException;
import it.sauronsoftware.jave.EncodingAttributes;
import it.sauronsoftware.jave.InputFormatException;

import java.io.File;

import com.sbl.bajw.common.web.WebContext;

public class AmrToMp3Util {
	
//	private static final String PATH = "http://183.239.137.213/imgs/";
	private static final String PATH = WebContext.getRequest().getSession().getServletContext().getInitParameter("UploadPath");

	public static void AmrToMp3(String oldFilePath, String newFilePath){
		File amr = new File(PATH + oldFilePath);
		File mp3 = new File(PATH + newFilePath);
		AudioAttributes audio = new AudioAttributes();
		Encoder encoder = new Encoder();
		
		audio.setCodec("libmp3lame");
		EncodingAttributes attrs = new EncodingAttributes();
		attrs.setFormat("mp3");
		attrs.setAudioAttributes(audio);
		
		try {
			encoder.encode(amr, mp3, attrs);
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (InputFormatException e) {
			e.printStackTrace();
		} catch (EncoderException e) {
			e.printStackTrace();
		}
		
	}
}
